package com.qianxun.module.datasource1.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianxun.framework.common.util.ObjectUtil;
import com.qianxun.module.base.bo.PageInfo;
import com.qianxun.module.datasource1.common.entity.DataTemplate;
import com.qianxun.module.datasource1.common.mapper.DataTemplateMapper;
import com.qianxun.module.datasource1.common.service.DataTemplateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 数据模板 对数据信息进行模板存储，以实现数据信息重用的目的 服务实现类
 * </p>
 *
 * @author admin
 * @since 2020-02-05
 */
@Service
public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, DataTemplate> implements DataTemplateService {

    @Override
    public IPage<DataTemplate> getPage(String userKey, String sign, String title, Integer current, Integer size) {
        LambdaQueryWrapper<DataTemplate> queryWrapper = new QueryWrapper<DataTemplate>().lambda().eq(DataTemplate::getCreatedKey ,userKey);
        if(!ObjectUtil.isEmpty(sign)){
            queryWrapper.eq(DataTemplate::getSign ,sign);
        }
        if(!ObjectUtil.isEmpty(title)){
            queryWrapper.eq(DataTemplate::getTitle ,title);
        }
        PageInfo pageInfo = PageInfo.build(current ,size);
        return page(new Page<>(pageInfo.getCurrent() ,pageInfo.getSize()) ,queryWrapper);
    }

    @Override
    public void add(DataTemplate dataTemplate) {
        save(dataTemplate);
    }

    @Override
    public boolean updateById(DataTemplate entity) {
        return super.updateById(entity);
    }
}
